/*
https://leetcode-cn.com/problems/corporate-flight-bookings/solution/hang-ban-yu-ding-tong-ji-by-leetcode-sol-5pv8/
 */

public class Solution1109 {

    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] record=new int[20005];
        int[] ans=new int[n];
        for (int[] booking : bookings) {
            record[booking[0]]+=booking[2];
            record[booking[1]+1]-=booking[2];
        }
        for (int i=0;i<n;i++){
            ans[i]=(i!=0?ans[i-1]+record[i+1]:record[i+1]);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1109().corpFlightBookings(new int[][]{{1,2,10},{2,3,20},{2,5,25}},5)[2]);
    }
}
